unit Login;

interface

uses
  Database, LoginScreen,
  WinTypes, WinProcs, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, DBTables, DB, Mask, SysUtils, Dialogs,
  ExtCtrls, WSocket, Menus, Grids,
  ImgList, jpeg;

type
    TFormLogin = class(TForm)
    MemoLicense: TMemo;
    TimerFocus: TTimer;
    TimerClearSkin: TTimer;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TimerFocusTimer(Sender: TObject);
    procedure TimerClearSkinTimer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    refreshingskin: boolean;
    procedure LoginScreen(which: integer; showsocket: boolean);
  end;

var
  FormLogin: TFormLogin;
  showingloginscreen, showingsocket: boolean;
  bufferpassword: string;
  screenLogin: TFormLoginScreen;

implementation

{$R *.DFM}

procedure TFormLogin.FormCreate(Sender: TObject);
begin
  Randomize;
  showingloginscreen:=false;
  refreshingskin:=false;
  showingsocket:=false;
  left:=0;
  top:=0;
  height:=0;
  width:=0;
end;

procedure TFormLogin.FormDestroy(Sender: TObject);
begin
  Datawell.abortdata:=true;
  if showingloginscreen then LoginScreen(0,false);
end;

procedure TFormLogin.FormShow(Sender: TObject);
var
  i: integer;
  work: string;
begin
  if not refreshingskin then begin
    Datawell.GenDate;
    //Check to see if the program is running from the desktop
    work:=extractfiledir(application.exename);
    work:=lowercase(work);
    i:=pos('desktop',work);
    if i > 0 then begin
      delete(work,1,i-1);
      if work = 'desktop' then begin
        messagedlg('If you wish to run Portal from the Windows desktop,'+#13+
          'please create a shortcut.  Do not copy the actual .EXE file',
        mtinformation,[mbok],0);
        close;
        exit;
      end;
    end;
    datawell.exedir:=work;
  end;
  LoginScreen(1,showingsocket);
end;

procedure TFormLogin.LoginScreen(which: integer; showsocket: boolean);
begin
  if which = 1 then begin
    if showingloginscreen then exit;
    screenLogin:=TFormLoginScreen.create(self);
    screenLogin.MenuToggleConnection.checked:=showsocket;
    screenLogin.MenuToggleConnection2.checked:=screenLogin.MenuToggleConnection.checked;
    screenLogin.BtnSocket.visible:=screenLogin.MenuToggleConnection.checked;
    screenLogin.show;
    showingloginscreen:=true;
    TimerFocus.enabled:=true;
  end
  else begin
    if not showingloginscreen then exit;
    showingsocket:=showsocket;
    screenLogin.free;
    showingloginscreen:=false;
  end;
end;

procedure TFormLogin.TimerFocusTimer(Sender: TObject);
begin
  TimerFocus.enabled:=false;
  if (showingloginscreen) and (screenLogin.visible) then screenLogin.setfocus;
end;

procedure TFormLogin.TimerClearSkinTimer(Sender: TObject);
begin
  TimerClearSkin.enabled:=false;
  refreshingskin:=true;
  FormShow(Sender);
  refreshingskin:=false;
end;

end.

